<?php
/**
 * 功能描述：	会员模块
 * @datetime	2020-05-04
 * @version   	v1.0
 * @author   	ZHL
 * @copyrigh  	2020 ZHL 版权所有
 */

class Web_MemberServe extends Model {

    /**
     * Notes:获取用户信息
     */
    public function getMemberInfo($where){
        if(!$where){
            return array();
        }
        $memberM = new Web_MemberModel();
        return $memberM->getMemberInfo($where);
    }

    /**
     * Notes: 根据用户昵称获取用户信息
     * User: ZHL
     * Date: 2020/5/5
     */
    function getMemberInfoName($nickName){
        if(!$nickName){
            return array();
        }
        $memberM = new Web_MemberModel();
        return $memberM->getMemberInfoName($nickName);
    }

    /**
     * Notes:用户信息修改
     * User: ZHL
     * Date: 2020/5/5
     */
    function updateInfo($param){
        if(empty($param)){
            return array('code'=>40000,'msg'=>'参数不能为空');
        }
        if(!isset($param['title']) || !$param['title']){
            return array('code'=>40001,'msg'=>'帐号不能为空');
        }
        if(!isset($param['pwd']) || !$param['pwd']) {
            return array('code' => 40002, 'msg' => '密码不能为空');
        }
        if(!isset($param['pwd2']) || !$param['pwd2']) {
            return array('code' => 40003, 'msg' => '确认密码不能为空');
        }
        if($param['pwd'] != $param['pwd2']){
            return array('code' => 40004, 'msg' => '密码和确认密码不一致');
        }
        if(!isset($param['code']) || !$param['code']) {
            return array('code'=>40005,'msg'=>'验证码不能为空');
        }
        $verifyCodeVal = SYS_SESSIONS_GET('w_img_code');
        if(!isset($verifyCodeVal['imgcode'])){
            return array('code'=>40006,'msg'=>'验证码不存在');
        }
        if($verifyCodeVal['imgcode'] != $param['code']){
            return array('code'=>40007,'msg'=>'图片验证码错误');
        }
        $member_info = SYS_SESSIONS_GET('member_info');
        if(!isset($member_info['id'])){
            return array('code'=>40008,'msg'=>'非法登录');
        }
        $id = $member_info['id'];

        /*$updateFlag = SYS_COOKIES_COUNT('member_update_flag', 3);
        if(!$updateFlag) {
            return array('code' => 40005, 'msg' => '今天次数已经超过三次');
        }*/

        $info = $this->getMemberInfoName($param['title']);
        if(!empty($info)){
            if($info['title'] == $param['title'] && $info['id'] != $id){
                return array('code' => 30000, 'msg' => '当前昵称已存在');
            }
        }
        $where['id'] = $id;
        $data['title'] = $param['title'];
        $data['pwd'] = setPwd($param['pwd']);
        $memberM = new Web_MemberModel();
        $request = $memberM->updateInfo($data, $where);
        if(!$request){
            return array('code' => 30001, 'msg' => '修改失败');
        }
        SYS_SESSIONS_DEL('member_info');
        return array('code'=>10000,'msg'=>'修改成功');

       /* $find = SYS_SESSIONS_GET('member_info');
        $find['title'] = $param['title'];
        $find['id'] = $id;
        SYS_SESSIONS_SET('member_info', $find);
        return array('code'=>10000,'msg'=>'修改成功');*/
    }

}